package com.carbohydrate42.kotlin_compose_demo

import androidx.navigation.NavHostController
import com.carbohydrate42.kotlin_compose_demo.config.Router
import kotlinx.coroutines.flow.MutableStateFlow

class MainState private constructor() {
    companion object {
        val instance by lazy { MainState() }
    }

    val mainPageSnackBarVisible = MutableStateFlow(false)
    val nav = MutableStateFlow<NavHostController?>(null)

    fun initNav(navHostController: NavHostController) {
        nav.value = navHostController
    }

    /**
     * 没有响应式的效果，只是为了方便获取当前的路由
     * 想要获得响应式需要在 compose 里面写
     */
    fun getCurrentRouter(): Router {
        return Router.fromRoute(nav.value?.currentBackStackEntry?.destination?.route)
    }


    fun toggleMainPageSnackBarVisible() {
        mainPageSnackBarVisible.value = !mainPageSnackBarVisible.value
    }
}